package com.itsu.application;

import cn.hutool.core.io.resource.ResourceUtil;
import com.itsu.application.controller.LoginController;
import com.itsu.application.framework.session.SessionContext;
import com.itsu.application.framework.websocket.WebSocketComponent;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {
	@Override
	public void start(Stage primaryStage) {
		try {
			FXMLLoader loader = new FXMLLoader(ResourceUtil.getResource("fxml/login.fxml"));
			Parent root = loader.load();
			LoginController controller = loader.getController();
			controller.setStage(primaryStage);
			Scene scene = new Scene(root);
//			scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
			primaryStage.setScene(scene);
			primaryStage.setTitle("V-Talk聊天室");
			primaryStage.show();
			primaryStage.setResizable(false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void init() throws Exception {
		SessionContext.generateSession();
	}

	@Override
	public void stop() throws Exception {
		SessionContext.getSession().destory();
		WebSocketComponent.close(0, "用户退出");
	}
}
